import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Layouts 1.1
import QtQuick.Controls.Styles 1.2
import QtQuick.Controls 2.0
import "../components"

Item {

    function tabSettingPage(idx){
        var list = layout_list.children
        var page = layout_mainpage.children
        for(let i = 0; i < list.length; i ++){
            if(i === idx){
                list[i].setSelect()
                page[i].visible = true
            }else{
                list[i].setUnselect()
                page[i].visible = false
            }
        }

        pageDevice.refresh()
    }
    Connections{
        target: mainwindow
        onTabSettings:{
            var list = layout_list.children
            // 初始化按钮样式
            for(let i = 0; i < list.length; i ++){

                list[i].button_color = "transparent"
                list[i].text_color = "#666666"
                list[i].button_color_select = "white"
                list[i].text_color_select = "#1677FF"
            }
            tabSettingPage(0)

        }
        onAskForTab:{
            if(mainwindow.mainPage !== 6) return
            mainwindow.permitTab()
        }
    }

    id: pageSettings
    anchors.fill: parent
    anchors.margins: 15*dp
    Item{                           // 上面的条
        id: layout_top
        height: 40*dp
        width: parent.width
        Text{
            text: "设置"
            font.pixelSize: config.fontsize + 4
            font.bold: true
            anchors.verticalCenter: parent.verticalCenter
        }
    }
    Rectangle{                      // 左侧的切换栏
        height: 60*dp * 6 + 30*dp
        width: 250*dp
        x: 0
        y: 50*dp
        color: "#EFEFF2"
        Column{
            id: layout_list
            anchors.fill: parent
            anchors.margins: 15*dp
            PushButton{
                title: "设备管理  "
                height: 60*dp
                width: parent.width + 20*dp
                button_icon: "qrc:/picture/settings_device.png"
                button_icon_select: "qrc:/picture/settings_device_select.png"
                onReleased: {
                    tabSettingPage(0)
                }
            }PushButton{
                title: "导出设置  "
                height: 60*dp
                width: parent.width + 20*dp
                button_icon: "qrc:/picture/settings_export.png"
                button_icon_select: "qrc:/picture/settings_export_select.png"
                onReleased: {
                    tabSettingPage(1)
                }
            }PushButton{
                title: "默认设置  "
                height: 60*dp
                width: parent.width + 20*dp
                button_icon: "qrc:/picture/settings_default.png"
                button_icon_select: "qrc:/picture/settings_default_select.png"
                onReleased: {
                    tabSettingPage(2)
                }
            }
            PushButton{
                title: "数据统计  "
                height: 60*dp
                width: parent.width + 20*dp
                button_icon: "qrc:/picture/settings_statistics.png"
                button_icon_select: "qrc:/picture/settings_statistics_select.png"
                onReleased: {
                    tabSettingPage(3)
                }
                visible: false
            }
            PushButton{
                title: "偏好设置  "
                height: 60*dp
                width: parent.width + 20*dp
                button_icon: "qrc:/picture/settings_preference.png"
                button_icon_select: "qrc:/picture/settings_preference_select.png"
                onReleased: {
                    tabSettingPage(4)
                }
            }PushButton{
                title: "实验恢复  "
                height: 60*dp
                width: parent.width + 20*dp
                button_icon: "qrc:/picture/settings_recover.png"
                button_icon_select: "qrc:/picture/settings_recover_select.png"
                onReleased: {
                    tabSettingPage(5)
                }
            }PushButton{
                title: "模型配置  "
                height: 60*dp
                width: parent.width + 20*dp
                button_icon: "qrc:/picture/settings_model.png"
                button_icon_select: "qrc:/picture/settings_model_select.png"
                onReleased: {
                    tabSettingPage(6)
                }
            }

        }


    }

    Rectangle{                      // 右侧的设置页面
        x: 250*dp
        y: 50*dp
        height: parent.height-50*dp
        width: parent.width-250*dp
        color: "white"
        id: layout_mainpage
        SettingsDevice{
            id: pageDevice
        }
        SettingsExport{

        }SettingsDefault{

        }SettingsStatus{

        }SettingsPreference{

        }SettingsExperiment{

        }SettingsModel{

        }
    }




}
